package com.example.shaidemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HotelContentActivity extends AppCompatActivity {

    private static final String TAG = "HotelContentActivity";
    LinearLayout supportLayout,objectLayout;
    ImageView supportImg,objectImg;
    TextView objectTxt,supportTxt;
    int cnt1,cnt2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hotel_content);
        //获取控件
        supportLayout = findViewById(R.id.support_layout);
        objectLayout = findViewById(R.id.object_layout);
        supportImg = findViewById(R.id.support_img);
        supportTxt = findViewById(R.id.support_txt);
        objectImg = findViewById(R.id.object_img);
        objectTxt = findViewById(R.id.object_txt);

        cnt1 = 0;
        cnt2 = 0;
        //选择可信时，改变图片、文本颜色
        supportLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG, "onClick: 选择支持!");
                cnt1 ++;
                if(cnt1 %2 ==1){
                    supportImg.setImageResource(R.drawable.support2);
                    supportTxt.setTextColor(0xffFF9546);
                }else{
                    //再次点击，取消选择
                    supportImg.setImageResource(R.drawable.support);
                    supportTxt.setTextColor(0xff1E1D1D);
                }

            }
        });

        //选择不可信时，改变图片颜色
        objectLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG, "onClick: 选择不可信");
                cnt2 ++;
                if(cnt2 %2 ==1){
                    objectImg.setImageResource(R.drawable.objectimg);
                }else{
                    //再次点击，取消选择
                    objectImg.setImageResource(R.drawable.nonsupport);
                }

            }
        });
    }
}